{extend name="layout/base" /}

{block name="style"}
<style type="text/css">
    /*.table>tbody>tr>td{padding: 3px 5px;}*/
</style>
{/block}

{block name="body"}
<div class="wrapper wrapper-content">

<div class="row animated fadeIn">
    <div class="col-xs-12">
        <div class="ibox box-success">
            <div class="ibox-title">
                <h5>管理员列表</h5>
            </div>
            <div class="panel-body ibox-content mainbox">
                <div class="row">
                    <div class="col-xs-3">
                        <a class="btn btn-primary addBtn" href="{:Url('/sysuser/add')}">添加管理员</a>
                    </div>
                </div>
                <table class="table table-striped table-bordered cs_table-hover m-t-sm">
                    <tr>
                        <th width="50">ID</th>
                        <th width="10%">用户名</th>
                        <th width="10%">昵称</th>
                        <th>Email</th>
                        <th>用户组</th>
                        <th>最后登录时间</th>

                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    {foreach $datas as $v}
                    <tr b-id="{$v['id']}">
                        <td>{$v['id']}</td>
                        <td title="创建时间:{$v['createtime']}">{$v['username']}</td>
                        <td>{$v['nickname']}</td>
                        <td>{$v['email']}</td>
                        <td>
                            {foreach $v['group'] as $val}
                            <span class="btn btn-xs btn-white">{$val}</span>
                            {/foreach}
                        </td>
                        <td>{$v['logintime']}</td>

                        <td><input class="i-checks sw-status" type="checkbox"{if $v['status']=='normal'} checked="checked"{/if} /></td>
                        <td>
                            <a href="{:Url('/sysuser/edit', ['id'=>$v['id']])}" class="editBtn">修改</a> |
                            <a href="{:Url('/sysuser/set_group', ['id'=>$v['id']])}">设置组</a> |
                            <a href="javascript:;" class="delBtn">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                </table>
            </div>
        </div>

    </div><!--col-md-->
</div>

</div><!--wrapper-->
{/block}

{block name="script"}
<!--公共JS-->
{include file="common/commjs" /}
<script type="text/javascript">

    $(function () {
        // 复选框按钮样式
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $('.mainbox .sw-status').on('ifChanged', function () {
            var dataPat = $(this).parents('tr:first');
            var rid = dataPat.attr('b-id');

            var parms = {
                'url': '{:Url("/sysuser/setter")}',
                'data': {}
            };
            if ($(this).is(':checked')) {
                parms['data'] = {'rid': rid,'field': 'status', 'val': 'normal'};
                sendAjax(parms);
            } else {
                parms['data'] = {'rid': rid,'field': 'status', 'val': 'hidden'};
                sendAjax(parms);
            }
        });

        $('.mainbox .delBtn').on('click', function () {
            var dataPat = $(this).parents('tr:first');
            var rid = dataPat.attr('b-id');
            var parms = {
                'url': '{:Url("/sysuser/del")}',
                'data': {'rid': rid}
            };
            var cbfun = function () {
                sendAjax(parms);
            };
            alertWarning('请谨慎操作,确定删除吗?', '', cbfun);
        });
        // 表单重置
        var formReset = function (former) {
            former[0].reset(); // former[0]转化成DOM对象
        };
    });
</script>
{/block}